package acm.pta5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * 思路，
 * 1.构建图
 * 2.遍历图，在遍历的过程中对每个next进行判断(不需要双向图)
 * 3.这个图需要哪些东西？
 * 节点：
 *   id，所有邻居节点
 */
public class T2_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] read = null;
        read = in.readLine().split(" ");
        Graph graph = new Graph(Integer.parseInt(read[0]));
        int n = Integer.parseInt(read[1]);
        int k = Integer.parseInt(read[2]);
        while (n-- > 0) {
            graph.insert(in.readLine().split(" "));
        }
        n = Integer.parseInt(in.readLine());
        while (n-- > 0) {
            read=in.readLine().split(" ");
            if (check(k,read)&&graph.dye(read)) {
                System.out.println("Yes");
            }else {
                System.out.println("No");
            }
        }
    }
    //检查颜色的个数是否合法
    public static boolean check(int k,String[] edge){
        Set<String> set=new HashSet<>();
        for (String s : edge) {
            set.add(s);
            if (set.size()>k)return false;
        }
        return set.size()==k;
    }

    static class Graph {
        List<Integer>[] lists;

        public Graph(int count) {
            lists =new LinkedList[count];
            for (int i = 0; i < lists.length; i++) {
                lists[i]=new LinkedList<>();
            }
        }

        public void insert(String[] edge) {
            int from = Integer.parseInt(edge[0]);
            int to = Integer.parseInt(edge[1]);
            lists[from-1].add(to-1);
//            lists[to-1].add(from-1);
        }

        public boolean dye(String[] colours) {
            for (int i = 0; i < lists.length; i++) {
                String colour = colours[i];
                for (Integer to : lists[i]) {
                    if (colour.equals(colours[to])){
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
